package org.gitman.agent.algorithms;

import java.util.Calendar;
import java.util.List;
import java.util.Random;

import org.gitman.agent.platform.Agent;
import org.gitman.agent.platform.AgentManager;
import org.gitman.agent.platform.AgentUtils;

import com.mxgraph.model.mxICell;
import com.mxgraph.view.mxGraph;

public class RandomAgent extends Agent {

	private Random rand;
	
	public RandomAgent(){
		name = "RandomAgent";
		description = "Completly random selecting child to move to/or stay";
		rand = new Random(Calendar.getInstance().getTimeInMillis());
	}
	
	@Override
	public Agent getInstance() {
		return new RandomAgent();
	}

	@Override
	public mxICell doStep(mxGraph graph, AgentManager agentManager) {
		mxICell child = null;
		List<mxICell> childs = AgentUtils.getAllChilds(currentPoint, graph, true);
		int childCount = childs.size() + 1;
		int select = rand.nextInt(childCount);
		if(select == childCount-1){
			child = currentPoint;
			agentManager.broadCastMessage("Hi boys I decided to stay here litle longer", this);
		}else{
			child = childs.get(select);
		}
		return child;
	}

}
